﻿@model Sheng.WeixinConstruction.Management.Shell.Models.ShakingLotteryDetailViewModel

@{
    ViewBag.MainMenu = "Campaign";
    ViewBag.LeftMenu = "ShakingLottery";

    ViewBag.Title = "摇一摇抽奖";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<script type="text/javascript" src="/Scripts/laydate/laydate.js"></script>

<script>

    var _id = getQueryString("id");

    $(document).ready(function () {
        if (_online == false)
            return;

    });

    function changePage(url) {
        window.location.href = url + "?id=" + _id;
    }

    function openPage(url) {

        window.open(url + "?id=" + _id);
    }

    function removeData() {
        if (_id == undefined || _id == "") {
            return;
        }

        var msg = "是否确认删除该活动？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/RemoveShakingLottery?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    layer.close(loadLayerIndex);
                    if (data.Success) {
                        window.location.href = "/Campaign/ShakingLottery_Ongoing";
                    } else {
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

    function endCampaign() {
        if (_id == undefined || _id == "") {
            return;
        }

        var msg = "是否确认结束该活动？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/EndCampaign?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    if (data.Success) {
                        if (data.Data == 0) {
                            window.location.reload();
                        }
                        else {
                            layer.close(loadLayerIndex);
                            switch (data.Data) {
                                case 1:
                                    layerAlert("此活动已经是结束过的活动。");
                                case 2:
                                    layerAlert("此活动还没有开始。");
                                default:
                                    layerAlert("开始失败");
                            }
                        }

                    } else {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

    function startShaking() {
        if (_id == undefined || _id == "") {
            return;
        }

        var msg = "是否确认打开参与通道？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/StartShaking?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    if (data.Success) {
                        window.location.reload();

                    } else {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

    function endShaking() {
        if (_id == undefined || _id == "") {
            return;
        }

        var msg = "是否确认打开参与通道？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/EndShaking?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    if (data.Success) {
                        window.location.reload();

                    } else {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

    function clearWinningList() {
        if (_id == undefined || _id == "") {
            return;
        }

        var msg = "警告：<br/>是否确认清除全部抽奖数据及中奖结果？注意清除操作无法恢复，一般用于清除测试期间产生的数据！"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/ClearShakingLotteryGiftWinningList?id=" + _id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    layer.close(loadLayerIndex);
                    if (data.Success) {
                        layerAlert("中奖结果已全部清除！");

                    } else {

                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

    function setPeriod(periodName, periodId) {

        var msg = "是否确认将当前活动周期设置为：" + periodName

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function () {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/SetShakingLotteryPeriod?campaignId=" + _id + "&periodId=" + periodId,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR) {
                    if (data.Success) {
                        window.location.reload();

                    } else {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest) {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

</script>

<div style="margin-top: 25px; margin-left: 10px;" class="font_black_24">
    @Model.CampaignBundle.Campaign.Name
</div>

<div style="margin-top: 30px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="td_ContentTab_active" style="width: 150px;">摘要</td>
            @if (Model.CampaignBundle.ShakingLottery.Mode == Sheng.WeixinConstruction.Infrastructure.EnumCampaign_ShakingLotteryMode.Period)
            {
                <td class="td_ContentTab" style="width: 150px;">
                    <a href="javascript:void(0)" class="a_black_16" onclick="changePage('/Campaign/ShakingLotteryPeriodList')">周期</a>
                </td>
            }
            <td class="td_ContentTab" style="width: 150px;">
                <a href="javascript:void(0)" class="a_black_16" onclick="changePage('/Campaign/ShakingLotteryGiftList')">奖品</a>
            </td>
            <td class="td_ContentTab" style="width: 150px;">
                <a href="javascript:void(0)" class="a_black_16" onclick="changePage('/Campaign/ShakingLotteryGiftWinningList')">中奖记录</a>
            </td>
            <td align="right">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="5" bgcolor="#EEEEEE" height="2"></td>
        </tr>
    </table>
</div>

<div style="margin-left: 20px; margin-right: 20px; margin-top: 10px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top: 20px;">
                    <tr>
                        <td width="50%" height="36" valign="top">创建时间：@Model.CampaignBundle.Campaign.CreateTime</td>
                        <td width="50%" valign="top">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="50%" height="36" valign="top">开始时间：@Model.CampaignBundle.Campaign.StartTime</td>
                        <td width="50%" valign="top">
                            @if (Model.CampaignBundle.Campaign.Status == Sheng.WeixinConstruction.Infrastructure.EnumCampaignStatus.End)
                            {
                                @:结束时间：@Model.CampaignBundle.Campaign.EndTime
                            }
                        </td>
                    </tr>
                    <tr>
                        <td height="36" valign="top">创建者：@Model.CampaignBundle.Campaign.CreateUserName</td>
                        <td valign="top">
                            仅关注者可参与：
                            @if (Model.CampaignBundle.Campaign.OnlyMember)
                            {
                                @:是
                            }
                            else
                            {
                                @:否
                            }
                        </td>
                    </tr>
                    @if (Model.CampaignBundle.ShakingLottery.Mode == Sheng.WeixinConstruction.Infrastructure.EnumCampaign_ShakingLotteryMode.Period)
                    {
                        <tr>
                            <td colspan="2" valign="top" height="36">
                                当前周期：
                                @if (Model.CurrentPeriod != null)
                                {
                                    @(Model.CurrentPeriod.Name)
                                }
                            </td>
                        </tr>
                    }
                    <tr>
                        <td colspan="2" valign="top" height="36">备注：@Model.CampaignBundle.Campaign.Remark</td>
                    </tr>
                </table>

            </td>
            <td width="280" align="right" valign="top">
                <img src="@Model.CampaignBundle.Campaign.ImageUrl" sty style="max-width:240px;">
            </td>
        </tr>
    </table>
</div>

<div class="divDotLine" style="margin-top: 20px; margin-left: 20px; margin-right: 20px;"></div>

<div style="margin-top: 25px;margin-left: 20px; margin-right: 20px;">
    <div style="float: right;">
        <input name="btnClearWinningList" type="button" class="btn_blue" id="btnClearWinningList" value="清除中奖结果" onclick="clearWinningList()" />
        @if (Model.CampaignBundle.Campaign.Status == Sheng.WeixinConstruction.Infrastructure.EnumCampaignStatus.Ongoing)
        {
            <input name="btnEnd" type="button" class="btn_red" id="btnEnd" value="结 束" onclick="endCampaign()" />
        }
        <input name="btnRemove" type="button" class="btn_red" id="btnRemove" value="删 除" onclick="removeData()" />
    </div>
    <div style="float: left">
        @if (Model.CampaignBundle.Campaign.Status == Sheng.WeixinConstruction.Infrastructure.EnumCampaignStatus.Ongoing)
        {
            if (Model.CampaignBundle.ShakingLottery.Mode != Sheng.WeixinConstruction.Infrastructure.EnumCampaign_ShakingLotteryMode.Period)
            {
                if (Model.CampaignBundle.ShakingLottery.Started == false)
                {
                    <input name="btnStart" type="button" class="btn_blue" id="btnStart" value="打开参与通道" onclick="startShaking()" />
                }
                else
                {
                    <input name="btnStart" type="button" class="btn_blue" id="btnStart" value="关闭参与通道" onclick="endShaking()" />
                }
            }

            <input name="btnModify" type="button" class="btn_blue" id="btnModify" value="编 辑" onclick="changePage('/Campaign/ShakingLotteryEidt')" />
            <input name="btnModify" type="button" class="btn_blue" id="btnModify" value="投 影" onclick="openPage('/Campaign/ShakingLotteryGiftWinningProjective')" />

        }
    </div>
    <div style="clear: both"></div>
</div>

@if (Model.CampaignBundle.Campaign.Status == Sheng.WeixinConstruction.Infrastructure.EnumCampaignStatus.Ongoing &&
    Model.CampaignBundle.ShakingLottery.Mode == Sheng.WeixinConstruction.Infrastructure.EnumCampaign_ShakingLotteryMode.Period)
{
    <div class="divDotLine" style="margin-top: 20px; margin-left: 20px; margin-right: 20px;"></div>
    <div style="margin-top: 25px;margin-left: 20px; margin-right: 20px;">
        <div>
            设置当前周期：
        </div>
        <div style="margin-top:10px;">
            <input type="button" class="btn_blue" value="无" onclick="setPeriod('无','')" />
            @foreach (var item in Model.PeriodList)
            {
                <input type="button" class="btn_blue" value="@item.Name" onclick="setPeriod('@item.Name','@item.Id')" />
            }
        </div>
    </div>
}



